package com.fr.report.core.headerfooter;

import com.fr.base.FRFont;
import com.fr.base.core.GraphHelper;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.util.StringTokenizer;

public class TextHFPaintable extends AbstractHFPaintable
{
  private TextHFElement textHFElement;

  public TextHFPaintable(TextHFElement paramTextHFElement)
  {
    this.textHFElement = paramTextHFElement;
  }

  public TextHFPaintable(Point2D paramPoint2D, TextHFElement paramTextHFElement)
  {
    super(paramPoint2D);
    this.textHFElement = paramTextHFElement;
  }

  public HFElement getHFElement()
  {
    return this.textHFElement;
  }

  public void paint(Graphics2D paramGraphics2D)
  {
    FRFont localFRFont = this.textHFElement.getFRFont();
    FontMetrics localFontMetrics = paramGraphics2D.getFontMetrics(localFRFont);
    Font localFont = paramGraphics2D.getFont();
    paramGraphics2D.setPaint(localFRFont.getForeground());
    paramGraphics2D.setFont(localFRFont);
    String str1 = this.textHFElement.getText();
    StringTokenizer localStringTokenizer = new StringTokenizer(str1, "\n");
    int i = str1.length();
    for (int j = 0; j < i; ++j)
    {
      int k = str1.charAt(j);
      if (k == 13)
      {
        if ((j < i - 1) && (str1.charAt(j + 1) == '\n'))
        {
          localStringTokenizer = new StringTokenizer(str1, "\r\n");
          break;
        }
        localStringTokenizer = new StringTokenizer(str1, "\r");
        break;
      }
      if (k == 10)
        break;
    }
    j = 0;
    while (localStringTokenizer.hasMoreElements())
    {
      String str2 = localStringTokenizer.nextToken();
      if (str2 == null)
        str2 = "";
      GraphHelper.drawString(paramGraphics2D, str2, getPaintLocation().getX(), j + getPaintLocation().getY() + localFontMetrics.getAscent());
      j += localFontMetrics.getHeight();
    }
    paramGraphics2D.setFont(localFont);
  }
}